
"""
    重定向
        redirect()

    url_for
        反解析，返回的是视图函数对应的路由地址
        url_for("视图函数", key=value)
"""

from flask import Flask, redirect, url_for

app = Flask(__name__)


@app.route("/")
def test1():
    # 重定向到外部
    return redirect("http://www.baidu.com")


@app.route("/test2")
def test2():
    # print(url_for("test4", token=1))
    response = redirect(url_for("test4", token=1))
    return response


@app.route("/test3")
def test3():
    response = redirect(url_for("test4", token=2))
    return response


@app.route("/test4/<int:token>")
def test4(token):
    if token == 1:
        return "test2 form, token = 1"
    elif token == 2:
        return "test3 form, token =2"
    else:
        return "myself"


if __name__ == '__main__':
    app.run(debug=True)

